<?php
    // +----------------------------------------------------------------------
    // | 海豚PHP框架 [ DolphinPHP ]
    // +----------------------------------------------------------------------
    // | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
    // +----------------------------------------------------------------------
    // | 官方网站: http://dolphinphp.com
    // +----------------------------------------------------------------------
    // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------

    namespace app\member\api;


    use app\common\controller\API;
    use app\member\model\MemberInfoModel;
    use think\Db;

    class Memberinfo extends API
    {

        protected $name = 'member_info';

        /**
         * 获取用户基本信息
         * api /member/memberinfo/getinfo
         *
         * @return \think\Paginator
         * @throws \think\exception\DbException
         */
        public function getinfo()
        {

            $this->result(MemberInfoModel::getMemberInfo(env('member_id')));
        }

        /**
         * 更新头像
         * api /member/memberinfo/setavatar
         *
         * @param  int $avatar 头像地址ID
         *
         * @return array 成功或失败
         */
        public function setavatar()
        {

            $data = $this->request->param();
            $this->check_validate($data,'Member.setavatar');
            $avatar = $data['avatar'];
            $re     = MemberInfoModel::update(['avatar' => $avatar],['member_id' => env('member_id')]);
            $re ? $this->success('头像跟新成功！') : $this->error('头像跟新失败！');
        }

        /**
         * 设置跟新个人信息
         * api /member/memberinfo/setinfo
         *
         * @param string $nickName 用户昵称
         *
         * @return  array $data  成功或失败
         */
        public function setinfo()
        {

            $data = $this->request->param();
            $this->check_validate($data,'Member.setinfo');
            $re = MemberInfoModel::update($data,['member_id' => env('member_id')]);
            $re ? $this->success('更新成功！') : $this->error('更新失败！');
        }

        /**
         * 设置个人支付信息
         * api /member/memberinfo/set_payinfo
         *
         * @param int    $validate_code 手机验证码
         *
         * @param string $alipay        支付宝账号
         * @param string $alipay_qr     支付宝二维码
         * @param string $wxpay         微信账号
         * @param string $wxpay_qr      微信二维码
         * @param string $bank_name     银行名称
         * @param string $card_name     持卡人姓名
         * @param string $bank_number   银行卡号
         *
         * @return  array $data  成功或失败
         */
        public function set_payinfo()
        {

            $data = $this->request->param();
            $this->check_validate($data,'Member.set_payinfo');
            $re = MemberInfoModel::update($data,['member_id' => env('member_id')]);
            $re ? $this->success('更新成功！') : $this->error('更新失败！');
        }

    }